package org.big;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

public class Main {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        // 1. 创建生产者，指定 Producer Group
        DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");
        // 2. 指定 NameServer 地址
        producer.setNamesrvAddr("192.168.1.10:9876"); // 替换为你的宿主机IP
        // 3. 启动生产者
        producer.start();

        // 4. 创建消息，指定 Topic、Tag 和消息体
        Message msg = new Message("TopicTest", "TagA", "Hello RocketMQ from Docker".getBytes());
        // 5. 发送消息
        SendResult sendResult = producer.send(msg);
        System.out.printf("%s%n", sendResult);

        // 6. 关闭生产者
        producer.shutdown();
    }
}
